import Store from 'react-native-store';

const repertories = Store.model('repertories');

export default class {
  constructor(name) {
    this._store = Store.model(name);
    // {id,pid,name,type,content}
  }

  getFiles(pid){

  }

  getContent(id){

  }

  static get(name){
    return new this(name);
  }

  static create(name) {
    return new Promise((resolve, reject) => {
      if (name == 'repertories') {
        reject('名称冲突，无法创建，请改用其他名称');
        return;
      }
      repertories.get({
        where: {
          and: [{
            name: {
              eq: name
            }
          }]
        }
      }).then(resp => {
        if (resp) {
          reject('名称已经存在，不能重复创建');
          return;
        }
        resolve(new this(name));
      }).catch(err=>{
        reject(err);
      });
    });
  }

  static getAll() {
    // repertories.find().then(resp => {});
    return repertories.find();
  }
}
